<template>
    <el-breadcrumb>
        <el-breadcrumb-item :to="{ path: 'home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>老师信息</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="serch">
        <el-input style="max-width: 600px" placeholder="输入搜索信息" v-model.trim="serchinfo">
            <template #prepend>
                <el-select placeholder="选择信息" v-model="select" style="width: 115px">
                    <el-option label="教师工号" value="teacher.teacherid" />
                    <el-option label="姓名" value="teacher.name" />
                    <el-option label="专业" value="submajor.name" />
                </el-select>
            </template>
            <template #append>
                <el-button @click="seach"><el-icon>
                        <Search />
                    </el-icon></el-button>
            </template>
        </el-input>
          <el-button @click="getalltea">查看所有老师</el-button>
    </div>
    <div class="data">
        <p style="margin-left:10px ;">老师信息</p>
        <el-table :data="tableData" stripe style="width: 100%">
            <el-table-column prop="teacherid" label="教师工号" />
            <el-table-column prop="name" label="姓名" />
            <el-table-column prop="phone" label="联系电话" />
            <el-table-column prop="major_name" label="专业" />
            <el-table-column prop="IDcard" label="身份证" min-width="120" />
            <el-table-column prop="nationality" label="民族" />
            <el-table-column label="操作" min-width="120" v-if="userstore.userinfo.roleid==1"> 
                <template #default>
                    <el-button type="primary" size="small">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
    <div class="pag">
        <el-pagination v-model:current-page="queryinfo.pagenum" v-model:page-size="queryinfo.pagesize"
            :page-sizes="[1, 2, 3, 4]" layout="total, sizes, prev, pager, next, jumper" :total="total"
            @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </div>
</template>
<script setup lang='ts'>
import { ref, onMounted } from 'vue'
import { teacherlist, seachteacher } from '@/apis/teacher'
import { ElMessage } from 'element-plus'
// @ts-ignore
import { Userstore } from '@/stores/user.js';
const userstore = Userstore()
const serchinfo = ref<string>('')
const select = ref<string>('')
const tableData = ref([{},])
const queryinfo = ref({
    pagenum: 1,
    pagesize: 2
})
const total = ref(0)
const seach = async () => {
    if (serchinfo.value == '' || select.value == '') return ElMessage({ type: 'warning', message: '请输入搜索的值' })
    const res = await seachteacher({ condition: select.value, val: serchinfo.value, ...queryinfo.value })
    total.value = res.data.total
    tableData.value = res.data.data
}
const handleSizeChange = (val: any) => {
    if (serchinfo.value != '') {
        seach()
    }
    else {
        getteacherlist()
    }
}
const handleCurrentChange = (val: any) => {
    if (serchinfo.value != '') { seach() }
    else {
        getteacherlist()
    }
}
const getteacherlist = async () => {
    const res = await teacherlist({ ...queryinfo.value })
    tableData.value = res.data.data
    total.value = res.data.total
}
const getalltea =()=>{
     serchinfo.value=''
    select.value =''
    getteacherlist()
}
onMounted(() => {
    getteacherlist()
})
</script>
<style lang='scss' scoped>
.serch {
    margin-top: 15px;

    .el-button {
        color: #fff;
        background-color: #43a0ff;
    }
}
</style>